home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MPW_TOOL / TOOLS / TOOLS_WI / ICON_8 / CALLING_ / ISTART.C < prev    next >
C/C++ Source or Header  |  1990-04-08  |  2KB  |  82 lines

  1. /*
  2.  *  Main program if Icon is called as a subprogram.
  3.  */
  4.  
  5. #include "../h/config.h"
  6. #include "../h/rt.h"
  7. #include "rproto.h"
  8.  
  9. #ifdef IconCalling
  10.  
  11. novalue main(argc,argv)
  12.  
  13. int argc;
  14. char *argv[];
  15.    {
  16.    int clargc;
  17.    char **clargv;
  18.    int i;
  19.    struct descrip darg;
  20.  
  21.    /*
  22.     * Set up standard Icon interface.  This is only necessary so that
  23.     *  Icon can behave normally as if it were the main program.
  24.     *  It is not necessary if Icon is called by a C program for another
  25.     *  purpose.
  26.     */
  27.    icon_setup(argc, argv, &i);
  28.    while (i--) {            /* skip option arguments */
  29.       argc--;
  30.       argv++;
  31.       }
  32.  
  33.    if (!argc) 
  34.       error("no icode file specified");
  35.  
  36.    /*
  37.     * Read in the icode file argv[1] and initialize the Icon system.
  38.     *  This must be done for any C program calling Icon.
  39.     */
  40.    icon_init(argv[1]);
  41.  
  42.    /*
  43.     * Skip the names of the executable and the file it processes.  This
  44.     *  is necessary only to get the right arguments from the command line
  45.     *  to call Icon as if it were the main program and hence provide
  46.     *  the correct values in the list that is the argument of Icon's main
  47.     *  procedure. This is not necessary if Icon is called from C for
  48.     *  another purpose.
  49.     */
  50.    clargv = argv + 2;
  51.    clargc = argc - 2;
  52.  
  53.    /*
  54.     * Set up a temporary stack and build the necessary list
  55.     *  to call main.
  56.     */
  57.    sp = stack + Wsizeof(struct b_coexpr);
  58.  
  59.    PushNull;
  60.    argp = (dptr)(sp - 1);
  61.    for (i = 0; i < clargc; i++) {
  62.       PushAVal(strlen(clargv[i]));
  63.       PushVal(clargv[i]);
  64.       }
  65.    Ollist(clargc, argp);
  66.  
  67.    /*
  68.     * Now that the list is computed, copy its descriptor off the
  69.     *  stack (which is about to be destroyed), reset the argument
  70.     *  pointer, and make the call to the Icon main procedure.
  71.     */
  72.  
  73.    darg = *argp;
  74.    argp = 0;
  75.    icon_call("main", 1, &darg);    /* return signal and value ignored */
  76.    c_exit(NormalExit);
  77.  
  78.    }
  79. #else                    /* IconCalling */
  80. static char x;                /* avoid empty module */
  81. #endif                    /* IconCalling */
  82.